/*
*************************************
* PocketGTT
*************************************
This file is part of PocketGTT.

PocketGTT is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

PocketGTT is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with PocketGTT.  If not, see <http://www.gnu.org/licenses/>.
*/

import QtQuick 1.0

Rectangle {
    //    property alias font: input.font
    property alias text: input.text
    //    property alias focus: input.focus
    //    signal textChanged(string text)

    id: lineEdit
    height: input.height + 6
    color: "white"
    radius: 5
    border.color: myWin.theme.blue_background
    border.width: 5

    Item {
        id: searchLogo
        anchors.left: parent.left
        anchors.top: parent.top
        height: parent.height
        width: parent.height

        Rectangle {
            id: bg
            color: myWin.theme.blue_background
            anchors.centerIn: parent
            height: parent.height
            width: parent.height
            //            radius: 5
            //            states: [
            //                State {
            //                    name: "blue"
            //                    when: !GTT.SelectMultipleStopsStatus && !myWin.statesMan.pageViewStatus
            //                    //            PropertyChanges { target: btnImgInfoBack; source: "qrc:ui/information_userguide.svg"}
            //                    PropertyChanges { target: bg; color: myWin.theme.blue_background}
            //                },
            //                State {
            //                    name: "backFromMultiPref"
            //                    when: GTT.SelectMultipleStopsStatus && !myWin.statesMan.pageViewStatus
            //                    //            PropertyChanges { target: btnImgInfoBack; source: "qrc:ui/back.svg"}
            //                    PropertyChanges { target: bg; color: myWin.theme.green_background}
            //                }

            //            ]
        }

        Image {

            fillMode: Image.PreserveAspectFit
            height: input.height // 72
            anchors.centerIn: parent
            source: "qrc:ui/search.svg"
        }
    }




    TextInput {
        id: input
        anchors.left: searchLogo.right
        anchors.leftMargin: 3
        anchors.top: parent.top
        anchors.topMargin: 3
        anchors.bottom: parent.bottom
        anchors.bottomMargin: 3
        color: "black"
        font.pixelSize: 24
        //        anchors.horizontalCenter: parent.horizontalCenter

        text: ""
    }

    MouseArea {
        anchors.fill: parent
        onClicked: {
            input.focus = true
            input.openSoftwareInputPanel();
        }
    }

    //    states: [
    //        State {
    //            when: input.cursorVisible
    //            PropertyChanges { target: lineEdit; color: "white" }
    //            PropertyChanges { target: input; color: "black" }
    //        },
    //        State {
    //            when: text == ""
    //            PropertyChanges { target: lineEdit; border.color: "grey" }
    //        }
    //    ]

    Keys.onReturnPressed: {
        //        lineEdit.textChanged(input.text)
        lineEdit.focus = true
        //        console.log("invio");
        GTT.searchByString(input.text);
        //        input.focus = false;
        input.closeSoftwareInputPanel();
    }
    Keys.onEnterPressed: {
        //        lineEdit.textChanged(input.text)
        lineEdit.focus = true
        GTT.searchByString(input.text);
        //        input.focus = false;
        input.closeSoftwareInputPanel();
    }

    states: [
        State {
            name: "blue"
            when: !GTT.SelectMultipleStopsStatus && !myWin.statesMan.pageViewStatus
            //            PropertyChanges { target: btnImgInfoBack; source: "qrc:ui/information_userguide.svg"}
            PropertyChanges { target: bg; color: myWin.theme.blue_background}
            PropertyChanges { target: lineEdit; border.color: myWin.theme.blue_background}
        },
        State {
            name: "backFromMultiPref"
            when: GTT.SelectMultipleStopsStatus && !myWin.statesMan.pageViewStatus
            //            PropertyChanges { target: btnImgInfoBack; source: "qrc:ui/back.svg"}
            PropertyChanges { target: bg; color: myWin.theme.green_background}
            PropertyChanges { target: lineEdit; border.color: myWin.theme.green_background}
        }

    ]

}
